from django.db import models

# Create your models here.
class Data_message(models.Model):
    TOTAL_CHANNEL = (
        (0,'微信'),
        (1,'支付宝'),
        (2,'QQ'),
    )
    
    TOTAL_STATUS = (
        (0,'无效'),
        (1,'有效'),
    )
    
    TOTAL_MSGTYPE = (
        (1,'文本'),
        (2,'图片'),
    )
    id = models.IntegerField(primary_key=True, db_column='id')
    title = models.CharField(max_length=20)
    description = models.CharField(max_length=50)
    picUrl = models.CharField(max_length=200)
    url = models.CharField(max_length=200)
    content = models.TextField(max_length=1023,verbose_name="欢迎词内容")
    msgType = models.PositiveIntegerField(choices=TOTAL_MSGTYPE,default=1,verbose_name="消息类型")
    qrcodeId = models.IntegerField()
    postTime = models.DateTimeField(auto_now=True,verbose_name="更新时间")
    state = models.PositiveIntegerField(choices=TOTAL_STATUS,default=1,verbose_name="是否有效")
    sysId = models.IntegerField()
    appId = models.IntegerField()
    channel = models.PositiveIntegerField(choices=TOTAL_CHANNEL,default=0,verbose_name="公众号频道")
    action = models.IntegerField()
    
    class Meta:
        app_label = "minik"
        verbose_name = u'欢迎词管理'
        verbose_name_plural = u'欢迎词管理'
        db_table = 't_data_message'
    
    def profile(self):
        small_content = self.content[:20]
        if small_content == self.content:
            return self.content
        else:
            return self.content[:20]+"..."
    profile.allow_tags = True
    profile.short_description = '欢迎词内容'
    